<?php
namespace Home\Controller;
use Think\Controller;
class AdminController extends CommonController {
    public function adminindex(){
		$this->display();
	}
	 public function tiezi(){
		$Tie=M('Tie');
		 $count=$Tie->count();
		 $Page = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(2)
		 $Page->setConfig('header','个记录');
		 $Page->setConfig('prev','上一页');
		 $Page->setConfig('next','下一页');
		 $show = $Page->show();// 分页显示输出	 
		 $arr = M('user  as  a')->join('lt_tie  as  b  on b.uid = a.id')->limit($Page->firstRow.','.$Page->listRows)->select();
		 $this->assign('arr',$arr);
		 $this->assign('show',$show);
		$this->display();
	}
	public function adminuser(){
		$User=M('User');
		 $count=$User->count();
		 $where['limit'] = array('neq',1);
		 $Page = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(2)
		$Page -> setConfig('first','首页');
		$Page -> setConfig('prev','上一页');
		$Page -> setConfig('next','下一页');
		$Page -> setConfig('link','indexpagenumb');//pagenumb 会替换成页码
		$Page -> setConfig('theme','%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
		 $show = $Page->show();// 分页显示输出	 
		 $arr=$User->limit($Page->firstRow.','.$Page->listRows)->where($where)->select();
		 $this->assign('arr',$arr);
		 $this->assign('show',$show);
		$this->display();
	}
	
	
	public function power(){
		$uid=$_GET['uid'];
		$User=M('User');		
	    $where['uid']=$uid;
		$User->status = 1;
	    $User->where($where)->save(); 
		$this->redirect('Admin/adminuser', array('cate_id' => 2), 5, '页面跳转中...');
	}
		public function delpower(){
		$uid=$_GET['uid'];
		$User=M('User');		
	    $where['uid']=$uid;
		$User->status = 0;
	    $User->where($where)->save(); 
		$this->redirect('Admin/adminuser', array('cate_id' => 2), 5, '页面跳转中...');
	}
	public function updatelimit(){
		$uid=$_GET['uid'];
		$User=M('User');		
	    $where['id']=$uid;
		$User->status = 1;
	    $arr=$User->where($where)->find();
		$this->assign('arr',$arr);
		$this->display();
	}	
	public function limit(){
		$uid=$_POST['uid'];
		$limit=$_POST['limit'];
		$User=M('User');			
	    $where['id']=$uid;
		$User->limit = $limit;
	    $User->where($where)->save(); 
		$this->redirect('Admin/adminuser', array('cate_id' => 2), 5, '页面跳转中...');
	}
	public function delete(){
		$uid=$_GET['uid'];
		$User=M('User');			
	    $where['id']=$uid;		
	    $User->where($where)->delete(); 
		$this->redirect('Admin/adminuser', array('cate_id' => 2), 5, '页面跳转中...');
	}
	public function zhiding(){
		$ding=1;
		$tid=$_GET['tid'];
		$Tie=M('Tie');
		$where['tid']=$tid;
		$Tie->ding = $ding;		
		$Tie->where($where)->save();
		$this->redirect('Admin/tiezi', array('cate_id' => 2), 1, '页面跳转中...');
	}
	public function jiajing(){
		$jing=1;
		$tid=$_GET['tid'];
		$Tie=M('Tie');
		$where['tid']=$tid;
		$Tie->jing = $jing;		
		$Tie->where($where)->save(); 
		$this->redirect('Admin/tiezi', array('cate_id' => 2), 1, '页面跳转中...');
	}
	public function delete_tie(){
		$tid=$_GET['tid'];
		$Tie=M('Tie');			
	    $where['tid']=$tid;		
	    $Tie->where($where)->delete(); 
		$this->redirect('Admin/tiezi', array('cate_id' => 2), 1, '页面跳转中...');
	}
	
	function getpage($count, $pagesize = 10) {
    $p = new Think\Page($count, $pagesize);
    $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
    $p->setConfig('prev', '上一页');
    $p->setConfig('next', '下一页');
    $p->setConfig('last', '末页');
    $p->setConfig('first', '首页');
    $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
    $p->lastSuffix = false;//最后一页不显示为总页数
    return $p;
}
}